home *** CD-ROM | disk | FTP | other *** search
- /*
- IC Text.c
-
-
- The pascal code uses a routine, NopCaretHook, to handle locked text resources. Basically
- it is a specialized caret drawing procedure that doesn't draw any caret (making the text
- item look like it is read-only).
-
- For the 68k code, I could have just implemented the routine in a function and make the body
- consist of asm statements. This would not work for the PPC version, however.
-
- And since you can't write a caret proc in a high level language (see TextEdit.h to find out
- why), I needed to implement the routine in assembler. Since Sym C++ 8.0 doesn't come
- with an assembler (version 8.0.4 is supposed to have one, but I haven't received my copy
- yet), that means that the only way to do it is with a 68k assembly routine.
-
- So I generated a small resource, 'NopC' id 128, which contains the code that would have been
- compiled from the original code. This resource is read in, load and locked high, and used
- whenever the hidden caret needs to be used.
-
- Note that the only reason I am not implementing this in the 68k code and using the resource
- for PPC code is because I don't like to have to maintain separate pieces of the code for each
- processor type.
- */
-
- #include <Scrap.h>
-
- #include "IC Text.h"
- #include "IC Dialogs.h"
-
- Handle __NopCaretHook=(Handle)0;
-
- OSErr TextCreate(Ptr* data,DialogPtr window,short item,short font,short size,Boolean locked){
- OSErr err;
- ItemDataPtr idp;
- Rect view,dest;
- SavedWindowInfo saved;
- Rect r;
- long wflags;
- Style face=0; // normal
-
- *data=(Ptr)0;
-
- idp=(ItemDataPtr)NewPtr(sizeof(ItemData));
- err=MemError();
-
- if (err==noErr){
- *data=(Ptr)idp;
- idp->window=window;
- idp->item=item;
- idp->te=(TEHandle)0;
- idp->active=true;
-
- EnterWindow(window,font,size,face,&saved);
-
- // get the normal rectangle
- GetDItemRect(window,item,&r);
-
- // convert to the long rectangle used by Waste
- dest=r;
- view=r;
-
- GetFontInfo(&(idp->fi));
-
- idp->lineheight=idp->fi.leading+idp->fi.ascent+idp->fi.descent;
-
- // round to exact line height
- dest.bottom=dest.top + ((dest.bottom-dest.top)/(idp->lineheight))*idp->lineheight;
-
- idp->te=TENew(&dest,&view);
-
- if (locked){
- // disable the caret
-
- if (__NopCaretHook==(Handle)0){
- // must load the caret hook proc
-
- // this is a 68k routine, so there is nothing really to do with it once it
- // is loaded
-
- __NopCaretHook=GetResource('NopC',128);
- err=ResError();
-
- if (err==noErr){
- // detach it so we keep it around
- DetachResource(__NopCaretHook);
-
- // move it high and lock it down
- HLockHi(__NopCaretHook);
- }
- }
-
- if (err==noErr){
- // no errors loading resource, set the caret hook proc
-
- /*
- We can do the following (set a proc ptr without building a routine
- descriptor) because we know the code is 68k; the MixedModeMgr
- will handle it correctly...
- */
- (*(idp->te))->caretHook=(CaretHookUPP)(*__NopCaretHook);
- }
- }
-
- TEAutoView(true,idp->te);
-
- ExitWindow(&saved);
-
- if (err!=noErr)
- TextDestroy(data);
- }
-
- return err;
- }
-
- void TextDestroy(Ptr* data){
- ItemDataPtr idp=(ItemDataPtr)(*data);
-
- if (*data!=(Ptr)0){
- if (idp->te!=(TEHandle)0)
- TEDispose(idp->te);
- DisposePtr(*data);
- *data=0;
- }
- }
-
- void TextDraw(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)data;
- Rect r;
-
- GetDItemRect(idp->window,idp->item,&r);
- EraseRect(&r);
- TEUpdate(&(*(idp->te))->viewRect,idp->te);
- }
-
- void TextActivate(Ptr data,Boolean activate){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- idp->active=activate;
- if (activate)
- TEActivate(idp->te);
- else
- TEDeactivate(idp->te);
- }
-
- void TextClick(Ptr data,EventRecord* er){
- ItemDataPtr idp=(ItemDataPtr)(data);
- ControlHandle control;
- short part;
-
- SetPort(idp->window);
- GlobalToLocal(&(er->where));
- part=FindControl(er->where,idp->window,&control);
- if (part==0){
- if (PtInRect(er->where,&(*(idp->te))->viewRect)){
- TEClick(er->where,(er->modifiers & shiftKey)!=0,idp->te);
- }
- }
- }
-
- void TextIdle(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- TEIdle(idp->te);
- }
-
- void TextKey(Ptr data,EventRecord* er){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- if ((er->modifiers & cmdKey)==0){
- TEKey((er->message & 0x00ff),idp->te);
- }
- }
-
- void TextSetSelect(Ptr data,long selStart,long selEnd){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- TESetSelect(selStart,selEnd,idp->te);
- }
-
- void TextGetSelect(Ptr data,long* selStart,long* selEnd){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- *selStart=(*(idp->te))->selStart;
- *selEnd=(*(idp->te))->selEnd;
- }
-
- void TextGetSize(Ptr data,long* text_size){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- *text_size=GetHandleSize((*(idp->te))->hText);
- }
-
- void TextInsert(Ptr data,Handle h){
- ItemDataPtr idp=(ItemDataPtr)(data);
- SignedByte s;
- OSErr err;
- short fea;
-
- s=HGetState(h);
- HLock(h);
- TEInsert(*h,GetHandleSize(h),idp->te);
- HSetState(h,s);
- }
-
- void TextGet(Ptr data,Handle h){
- ItemDataPtr idp=(ItemDataPtr)(data);
- long source_size;
- Handle source;
-
- source=(Handle)TEGetText(idp->te);
- source_size=GetHandleSize(source);
- SetHandleSize(h,source_size);
- if (MemError()==noErr){
- BlockMoveData(*source,*h,source_size);
- } else
- SetHandleSize(h,0);
- }
-
- void TextMove(Ptr data,Rect* r){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- (*(idp->te))->viewRect=*r;
- (*(idp->te))->destRect=*r;
-
- TECalText(idp->te);
- }
-
- void TextCut(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- TECut(idp->te);
- ZeroScrap();
- TEToScrap();
- }
-
- void TextCopy(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- TECopy(idp->te);
- ZeroScrap();
- TEToScrap();
- }
-
- void TextPaste(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- if (TEFromScrap()==noErr)
- TEPaste(idp->te);
- }
-
- void TextClear(Ptr data){
- ItemDataPtr idp=(ItemDataPtr)(data);
-
- TEDelete(idp->te);
- }
-
-
-
-
-
-